// component/site-monitoring/index.ts
import { getListAll } from '../../api/site-monitoring'
import type { siteList } from '../../type/type'
export interface list {
  text: String,
  value: Number | String
}
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    option1: [
      { text: '全部站', value: '-1' },
      { text: '热源站', value: '1' },
      { text: '换热站', value: '2' },
    ] as list[],
    option2: [
      { text: '全部', value: '0' },
      { text: '报警', value: '1' },
      { text: '正常', value: '2' },
    ] as list[],
    stationType: '-1' as String,
    type: '0' as String,
    searchstring: '' as String,
    comID: -1 as Number,
    userID: -1 as Number,
    list: [] as siteList[],
    isFresh: false as Boolean
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async getAllList() {
      let type = this.data.type;
      let stationType = this.data.stationType
      let comID = this.data.comID
      let userID = this.data.userID
      let searchstring = this.data.searchstring
      const res = await getListAll('1', stationType, comID, userID, searchstring)
      if (res.data.code == 1) {
        this.setData({
          list: res.data.data,
          isFresh: false
        })
        // console.log(this.data.list)
      }
      console.log(res)
    },
    search() {
      this.getAllList();
    },
    onStationType() {
      this.getAllList();
    },
    onType() {
      this.getAllList();
    },
    fresh() {
      this.setData({
        isFresh: true
      })
      this.getAllList();
    },
    onDetail(e: any) {
      console.log(e)
      let type = e.currentTarget.dataset.type
      let id = e.currentTarget.dataset.id
      let warnCode = e.currentTarget.dataset.warncode
      if (warnCode == 0) {
        wx.navigateTo({
          url: '/pages/siteDetail/siteDetail?type=' + type + '&id=' + id
        })
      } else {
        wx.navigateTo({
          url: '/pages/alarmDetail/alarmDetail?type=' + type + '&id=' + id
        })
      }
      // console.log(e)
    }
  },
  //小程序声明周期
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行

    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  pageLifetimes: {
    show: function () {
      // 页面被展示
      this.setData({
        comID: wx.getStorageSync("userInfo").data.comID,
        userID: wx.getStorageSync("userInfo").data.userID
      })
      this.getAllList();
    },
    hide: function () {
      // 页面被隐藏
    },
    resize: function (size) {
      // 页面尺寸变化
    }
  }
})